home *** CD-ROM | disk | FTP | other *** search
/ Gold Medal Software 2 / Gold Medal Software Volume 2 (Gold Medal) (1994).iso / prog / asm_n_z.arj / XPRT.ASM < prev    next >
Assembly Source File  |  1987-09-27  |  26KB  |  1,007 lines

  1.  name XPRT
  2.  page 62,128
  3.  title XPRT -- Print a File
  4.  
  5. ;XPRT -- a utility to print out text files with titles and page numbers
  6. ;on the current list device.  The high bit of all characters is stripped
  7. ;so that raw WordStar or other word processing files can be listed.
  8. ;That is, unless the /X (Translate) option is specified, then the
  9. ;special characters (>128) are translated to GEMINI STAR compatable
  10. ;format.  This should be generalized but it will do what I want.
  11. ;This translate is intended to convert files formatted for the screen
  12. ;or IBM graphics to Gemini compatability ... should work for most cases.
  13. ;Embeded form feeds codes are recognized, and tabs are expanded.
  14. ;Unknown control codes (such as the ^B and ^U codes found in WordStar
  15. ;documents) are discarded.
  16. ;
  17. ;XPRT has been designed to work with the Gemini Start 10X printer.
  18. ;Some functions should also work on EPSON printers.  Specifically,
  19. ;the basic XPRT operation is OK and the /C and /N options should
  20. ;work (but not /I, /E, /8).  Full compatability with EPSON
  21. ;will require modification of this program.
  22. ;
  23. ;This program is desinged to operate as a COM file under PC-DOS.
  24. ;It has been tested with PC-DOS 3.1 on an IBM XT.
  25.  
  26.  
  27. ;Used in the form:
  28. ;      A>XPRT path\filename.ext  [/S] [/8] [/f=3] [/I] [/N] ["title text"]
  29. ;          (items in brackets are optional)
  30. ;        /T -- output set to terminal (the console or screen)
  31. ;        /C -- set COPY option
  32. ;        /6 -- set 6 lines/inch spacing
  33. ;        /8 -- set 8 lines/inch spacing
  34. ;        /f=1 -- 10cpi
  35. ;        /f=2 -- 12cpi
  36. ;        /f=3 -- 15cpi
  37. ;        /f=4 -- 17cpi
  38. ;        /f=5 -- 20cpi
  39. ;        /S -- strip high order bits from input.
  40. ;        /X -- set Gemini Translate of special characters
  41. ;        /I -- set indent
  42. ;        /N -- add sequence numbers
  43. ;        /z -- suppress eof (1ah) check -- read until len=0
  44. ;        /d=1 -- Epson
  45. ;        /d=2 -- Gemini Star 10x
  46. ;        /d=3 -- NEC P6/p7
  47. ;        /d=4 -- IBM ProPrinter
  48.  
  49. ;NOTE ---
  50. ;    1. This program requires PC-DOS 2.0 or later.
  51. ;    2. The following applies to the original LIST program:
  52. ;    Version 1.0 February 28, 1984
  53. ;    Copyright (c) 1984 by Ray Duncan
  54. ;    May be freely reproduced for noncommercial use.
  55.  
  56.  
  57. ;STATUS --
  58. ;      Updated and extensively modified by Gene Czarcinski
  59. ;      ... This is based on Ray Duncan's LIST program.
  60. ;
  61. ;      Version 2.3, Gene Czarcinski,  October 10, 1984 - created
  62. ;      Version 2.4, Gene Czarcinski,  December 3, 1984 - updated
  63. ;     ... add help ('?') facility
  64. ;     ... default title is the filename
  65. ;     ... suppress leading formfeed
  66. ;      Version 2.5, Gene Czarcinski, May 24, 1986 - updated
  67. ;     ... add /X option
  68. ;     ... fix read_block to handle file with no ^Z correctly
  69. ;     ... no final ff if output to terminal
  70. ;      Version 2.6, Gene Czarcinski, June 8, 1986 - updated
  71. ;     ... support PICA, ELITE and COMPRESSED char sets
  72. ;     ... no RESET .. init printer each time
  73. ;      Version 2.7, Gene Czarcinski, June 9, 1986 - updated
  74. ;     ... finish /N support
  75. ;     ... misc. cleanup
  76. ;      Version 3.0, Gene Czarcinski, February 15, 1987 -
  77. ;     ... renamed from LIST to XPRT
  78. ;     ... add /S to strip high order bits from input.
  79. ;     ... add translate (/X) option
  80. ;      Version 4.0, Gene Czarcinski, September 28, 1987 - updated
  81. ;     ... add multi printer type support (especially NEC p6)
  82. ;     ... add capability to just copy input (with printer control)
  83. ;     ... change parm analysis: can be option groups and allow
  84. ;         anywhere in command-line input string ... the slash (/) is
  85. ;         still the only option specifier
  86. ;     ... fixup specifying command -- MASM 5.0
  87. ;     ... optionally suppress EOF (1ah) check
  88.  
  89.  
  90. cr    equ    0dh        ;ASCII CR
  91. lf    equ    0ah        ;ASCII LF
  92. ff    equ    0ch        ;ASCII FormFeed
  93. eof    equ    01ah        ;end-of-file marker
  94. tab    equ    09h        ;ASCII tab char
  95.  
  96. blksize equ    1024        ;size of block reads from input file
  97. linesize equ    250        ;max length of output line
  98. heading_lines equ 3        ;number of lines in page heading
  99.  
  100. console_handle equ 1        ;handle of standard console device
  101. error_handle   equ 2        ;not re-directable...std error output
  102. list_handle    equ 4        ;handle of standard list device
  103.  
  104. ;----------------------------------------------------------------------------
  105.  
  106. xprt    segment para public 'CODE'
  107.  
  108.     assume cs:xprt,ds:xprt,es:xprt
  109.  
  110.     org    0080h        ; location of command tail
  111. command LABEL    BYTE        ;buffer for command tail
  112.  
  113.     org    0100h
  114.  
  115. main    proc    far        ;entry point from PC-DOS
  116.     jmp    starts
  117. ;----------------------------------------------------------------------------
  118.  
  119. printer_type    db    3    ;0=none (screen)
  120.                 ;1=Epson FX
  121.                 ;2=Gemini Star 10x
  122.                 ;3=NEC p6/p7
  123.                 ;4=IBM Proprinter
  124.  
  125. flg_font    db    1    ;font type:
  126.                 ; 1=10cpi, 2=12cpi, 3=15cpi, 4=17cpi, 5=20cpi
  127. flg_lpi     db    6    ;lines per inch
  128. flg_indent    db    0    ;indenting flag
  129. flg_copy    db    0    ; Copy Option
  130. flg_no_eof    db    0    ; eof skip check
  131.  
  132. input_name    db    64 dup (0)    ;buffer for input filespec
  133. input_handle    dw    0        ;token from PC-DOS for input file
  134. output_handle    dw    list_handle    ;the handle of the output file
  135. input_ptr    dw    0        ;pntr to input    buffer
  136. output_ptr    dw    0        ;pntr to output buffer
  137. column        dw    0        ;column count for tab processing
  138. pagesize    dw    60        ;lines/page
  139. linenumber    dw    0        ;for /N
  140. linecount    dw    99        ;line counter for current page ...
  141.                     ;init to pagesize to force eject
  142. pagecount    dw    0        ;current page number
  143. titlecount    db    0        ;count for scanning title
  144. term_switch    dw    0        ;set to -1 if /T
  145. xlate_switch    dw    0        ;set to -1 if /X
  146. strip_switch    dw    0        ;set to -1 if /S
  147. num_switch    dw    0        ;set to -1 if /N
  148. ttl_flag    dw    0        ;set to -1 if title from command line
  149.  
  150. init_printer    db    32 dup (0)    ;set by set_option
  151. init_printer_length dw 0
  152.  
  153. msg1        db    cr,lf,'Cannot find INPUT file.',cr,lf,'$'
  154. msg2        db    cr,lf,'Missing filename.',cr,lf,'$'
  155. helpmsg db    cr,lf,'---XPRT Version 4.0, September 28, 1987---'
  156.  db cr,lf,cr,lf
  157.  db 'XPRT <path\filename.ext> [/t] [/n] [/i] ... "..title.."'
  158.  db cr,lf
  159.  db cr,lf,'  /c - plain COPY option .. no pagination'
  160.  db cr,lf,'  /t - set output to terminal/screen'
  161.  db cr,lf,'  /f=n font select .. n selects cpi value'
  162.  db cr,lf,'     n=1 -- 10cpi (default)   n=4 -- 17cpi'
  163.  db cr,lf,'     n=2 -- 12cpi             n=5 -- 20cpi'
  164.  db cr,lf,'     n=3 -- 15cpi'
  165.  db cr,lf,'  /6 - set 6 lines/inch'
  166.  db cr,lf,'  /8 - set 8 lines/inch'
  167.  db cr,lf,'  /i - set printer indent mode'
  168.  db cr,lf,'  /s - strip input'
  169.  db cr,lf,'  /z - skip eof check'
  170.  db cr,lf,'  /x - set translate mode'
  171.  db cr,lf,'  /n - sequence number the output lines'
  172.  db cr,lf,'  /d=n - set output printer type'
  173.  db cr,lf,'     n=1 Epson              n=3 NEC P6/P7'
  174.  db cr,lf,'     n=2 Gemini Star 10x    n=4 IBM Proprinter'
  175.  db cr,lf
  176. helplen equ    $-helpmsg
  177.  
  178. help_pt db cr,lf,'Printer Type: '
  179. help_ptl equ $-help_pt
  180. help_pt0 db 'None'
  181. help_pt0l equ $-help_pt0
  182. help_pt1 db 'Epson FX'
  183. help_pt1l equ $-help_pt1
  184. help_pt2 db 'Gemini Star 10x'
  185. help_pt2l equ $-help_pt2
  186. help_pt3 db 'NEC P6/P7'
  187. help_pt3l equ $-help_pt3
  188. help_pt4 db 'IBM Proprinter'
  189. help_pt4l equ $-help_pt4
  190. help_ptx db cr,lf
  191. help_ptxl equ $-help_ptx
  192.  
  193. ;    0   1    2   3    4   5    6   7    8   9    A   B    C   D    E   F
  194. Xtbl db 000,001,002,003,004,005,006,007,008,009,010,011,012,013,014,015 ;00
  195.      db 016,017,018,019,020,021,022,023,024,025,026,027,028,029,030,031 ;10
  196.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;20
  197.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;30
  198.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;40
  199.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;50
  200.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;60
  201.      db 032,032,032,032,032,032,032,032,032,032,032,032,032,032,032,032 ;70
  202.      db 239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239 ;80*
  203.      db 239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239 ;90*
  204.      db 239,239,239,239,239,239,239,239,239,239,239,239,239,239,239,239 ;A0*
  205.      db 20h,20h,20h,245,249,249,249,242,242,249,245,242,247,247,247,242 ;B0*
  206.      db 246,248,243,244,241,250,244,244,246,240,248,243,244,241,250,248 ;C0*
  207.      db 248,243,243,246,246,240,240,250,250,247,240,239,231,233,234,232 ;D0*
  208.      db 20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h ;E0*
  209.      db 20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,20h,174,20h ;F0*
  210.  
  211.  
  212. input_buffer_len dw    0        ;length read
  213. input_buffer    db    blksize dup (?) ;deblocking buffer for input file
  214. output_number    db    'nnnnn>'
  215. output_buffer    db    linesize dup (?); output buffer for list device
  216.  
  217. heading_buffer    db    00        ;initial=null, then formfeed
  218. heading_month    db    '00/'
  219. heading_day    db    '00/'
  220. heading_year    db    '00  '
  221. heading_hh    db    '00.'
  222. heading_mm    db    '00  '
  223. heading1    db    40 dup (' ')    ;filled in with user's title
  224. max_title    equ    $-heading1
  225.         db    '  '
  226.         db    '       Page '
  227. heading2    db    '_____',cr
  228.         db    heading_lines dup (lf)
  229. heading_length    equ    $-heading_buffer
  230.  
  231. ;-------Main Line Code-------------------------------------------------------
  232.  
  233. starts: push    ds        ;save DS:0000 for final
  234.     xor    ax,ax        ;return to PC-DOS
  235.     push    ax
  236.  
  237.     call    get_date    ;insert formatted date/time into title
  238.     call    get_title    ;get maining title from command line tail
  239.     call    get_option    ;process (switch) options
  240.     call    get_filename    ;get path anbd file spec. for input file
  241.                 ;from the command line tail.
  242.     mov    ax,es        ;set DS=ES for remainder of pgm
  243.     mov    ds,ax
  244.  
  245.     jnc    main15        ;jump, got accesptable name
  246.     mov    dx,offset msg2    ;missing or illegal filespec
  247.     jmp    main9        ;print error msg and exit
  248.  
  249. main15: mov    al,input_name    ;check if help wanted
  250.     cmp    al,'?'
  251.     jne    main19        ;continue
  252.     call    display_info
  253.     ret            ;return to DOS
  254.  
  255. main19: call    open_input    ;now try to open the inpuyt file
  256.     jnc    main2        ;jump if opened OK
  257.     mov    dx,offset msg1    ;open failed for input file
  258.     jmp    main9        ;print error msg and exit
  259.  
  260. main2:    call    set_option
  261.  
  262.     cmp    term_switch,0    ;console (/s) or printer ?
  263.     je    main22        ;printer
  264.  
  265.     mov    ax,console_handle ; init for console
  266.     mov    output_handle,ax
  267.     mov    al,0        ;if console, set formfeed to null
  268.     mov    heading_buffer,al
  269.     jmp    main25        ;skip printer init code
  270.  
  271. main22: mov    dx,offset init_printer
  272.     mov    cx,init_printer_length
  273.     mov    bx,output_handle
  274.     mov    ah,40h
  275.     int    21h
  276.  
  277. main25:             ;initialize input deblocking buffer
  278.     call    read_block    ;get first block
  279.     mov    output_ptr,0    ;set output to null
  280.     mov    linenumber,0
  281.     cmp    input_buffer_len,0
  282.     jne    main3
  283.     jmp    main8
  284.  
  285. main3:                ;file successfully opened.
  286.                 ;now print it.
  287.     call    get_char    ;read 1 char from input
  288.     cmp    al,20h        ;is it a control code?
  289.     jae    main4        ;no, write it to main device.
  290.                 ;yes, it is a control code
  291.     cmp    al,eof        ;is it e-o-f marker?
  292.     je    main8        ;yes, go close files
  293.     cmp    al,tab        ;is it a tab char?
  294.     je    main5        ;yes, go to special processing.
  295.     cmp    al,ff        ;us it a FormFeed?
  296.     je    main54        ;yes, goto special processing
  297.     cmp    al,cr        ;if it is an illegal control code,
  298.     jne    main3        ;discard it and get next char.
  299.     mov    al,lf        ;insert a line feed
  300.     call    put_char
  301.  
  302.     mov    al,cr        ;restore reg
  303.     call    put_char
  304.  
  305.     mov    column,0    ;if C/R, store it into output
  306.     jmp    main53        ;string and initialize column output.
  307.  
  308. main4:    inc    column        ;count chars sent on this line.
  309.  
  310. main45: call    put_char    ;write this char into forming output string.
  311.  
  312.     cmp    output_ptr,linesize-1  ;about to overflow?
  313.     je    main53        ;yes,force print to buffer.
  314.     jmp    main3        ;no,get next char
  315.  
  316. main5:    mov    ax,column    ;process tab char .. let DX:AX=column count
  317.     cwd
  318.     mov    cx,8        ;divide by 8
  319.     idiv    cx
  320.     sub    cx,dx        ;remainder is in DX
  321.     add    column,cx    ;update column pntr
  322. main51:             ;8 minus the remainder.
  323.     push    cx        ;gives the number of spaces
  324.     mov    al,20h        ;to send out to move to
  325.     call    put_char    ;the next tyab position.
  326.     pop    cx        ;restore space count
  327.     loop    main51
  328.     jmp    short main3    ;get next char
  329.  
  330.  
  331. main53:         ;line-feed detected, interprete as print command.
  332.     call    heading_maybe    ;print heading if needed.
  333.     call    write_line    ;print output buffer
  334.     jmp    main3        ;continue
  335.  
  336. main54:             ;handle a form-feed
  337.     call    write_maybe    ;FormFeed detected ..
  338.                 ;if anything waiting in output buffer,
  339.                 ;print it first.
  340.     call    print_heading    ;new page and print title
  341.     jmp    main3        ;continue
  342.  
  343. main8:                ;end-of-file detected
  344.     call    write_maybe    ;print if anything waiting ...
  345.  
  346. main81: cmp    term_switch,0    ;Console output?
  347.     jne    main83        ;yes, skip ff
  348.     mov    al,ff        ;send FormFeed to finish maining
  349.     call    put_char
  350.     call    write_line
  351. main83: mov    bx,input_handle ;BX=handle --- close the input file
  352.     mov    ah,3eh        ;close
  353.     int    21h
  354. main85: ret            ;return to PC-DOS
  355.  
  356. main9:            ;come here to print error message
  357.     mov    ah,9        ;and return to dos
  358.     int    21h
  359.     ret
  360.  
  361. main    endp
  362.  
  363. display_info proc near        ;display some help info
  364.     mov    dx,offset helpmsg
  365.     mov    cx,helplen
  366.     mov    bx,console_handle
  367.     mov    ah,40h
  368.     int    21h
  369.     mov    dx,offset help_pt
  370.     mov    cx,help_ptl
  371.     mov    bx,console_handle
  372.     mov    ah,40h
  373.     int    21h
  374.     mov    dx,offset help_pt1
  375.     mov    cx,help_pt1l
  376.     cmp    printer_type,1
  377.     je    info_9
  378.     mov    dx,offset help_pt2
  379.     mov    cx,help_pt2l
  380.     cmp    printer_type,2
  381.     je    info_9
  382.     mov    dx,offset help_pt3
  383.     mov    cx,help_pt3l
  384.     cmp    printer_type,3
  385.     je    info_9
  386.     mov    dx,offset help_pt4
  387.     mov    cx,help_pt4l
  388.     cmp    printer_type,4
  389.     je    info_9
  390.     mov    dx,offset help_pt0
  391.     mov    cx,help_pt0l
  392. info_9: mov    bx,console_handle
  393.     mov    ah,40h
  394.     int    21h
  395.     mov    dx,offset help_ptx
  396.     mov    cx,help_ptxl
  397.     mov    bx,console_handle
  398.     mov    ah,40h
  399.     int    21h
  400.     ret
  401. display_info endp
  402.  
  403.  
  404. get_filename proc near        ;process name of the input file
  405.                 ;DS:SI <- addr command line
  406.  
  407.     mov  si,offset command    ;ES:DI <- addr filespec buffer
  408.     mov    di,offset input_name
  409.     cld
  410.     lodsb            ;any command line present?
  411.     or    al,al        ;return error status if not.
  412.     jz    get_filename9
  413. get_filename1:    lodsb        ;scan over leading blanks to file name
  414.     cmp    al,20h        ;blank?
  415.     je    get_filename1    ;yes, keep scanning.
  416.     cmp    al,cr        ;C/R?
  417.     jne    get_filename1a
  418. get_filename1x:
  419.     jmp    get_filename9
  420. get_filename1a:
  421.     cmp    al,'/'          ;or switch?
  422.     jne    get_filename1b
  423. get_filename1aL:
  424.     lodsb
  425.     cmp    al,cr
  426.     je    get_filename1x
  427.     cmp    al,' '
  428.     jne    get_filename1aL
  429.     jmp    get_filename1
  430. get_filename1b:
  431.     cmp    al,'"'          ;or quote mark (filename missing)
  432.     jne    get_filename2    ;no, found filename
  433. get_filename1bL:
  434.     lodsb
  435.     cmp    al,cr
  436.     je    get_filename1x
  437.     cmp    al,'"'
  438.     jne    get_filename1bL
  439.     jmp    get_filename1
  440.  
  441. get_filename2:
  442.     push    si        ;save for title
  443.     push    ax
  444.  
  445. get_filename4: stosb        ;found first char of name
  446.                 ;move last char to output filename buffer
  447.     lodsb            ;check next char found
  448.     cmp    al,cr        ;C/R yet?
  449.     je    get_filename5    ;yes,exit with success code
  450.     cmp    al,'"'          ;quote encountered?
  451.     je    get_filename5
  452.     cmp    al,20h        ;blank?
  453.     jne    get_filename4    ;no, keep moving chars
  454. get_filename5:
  455.     pop    ax        ;get saved values (and restore stack)
  456.     pop    si
  457.     test    ttl_flag,-1    ;was a title specified?
  458.     jnz    get_filename8    ;yes, exit.
  459.     mov    di,offset heading1
  460.     mov    bl,max_title+1
  461.     mov    titlecount,bl
  462. get_filename7: stosb
  463.     lodsb
  464.     dec    titlecount
  465.     jz    get_filename8
  466.     cmp    al,cr        ;test for end
  467.     je    get_filename8
  468.     cmp    al,'"'
  469.     je    get_filename8
  470.     cmp    al,20h
  471.     jne    get_filename7
  472. get_filename8:
  473.     clc            ;for success flag
  474.     ret
  475. get_filename9:            ;exit with carry=1 for error flag
  476.     stc
  477.     ret
  478. get_filename endp
  479.  
  480.  
  481. get_title proc near        ;process title for listing
  482.     mov    al,max_title+1
  483.     mov    titlecount,al
  484.     mov    si,offset command    ;DS:SI <- addr command line
  485.     mov    di,offset heading1   ;ES:DI <- addr page heading buffer
  486.     cld
  487.     lodsb            ;any command line present?
  488.     or    al,al        ;no, exit
  489.     jz    get_title3
  490. get_title1:    lodsb        ;scan for leading <"> to find title.
  491.     cmp    al,cr        ;C/R?
  492.     je    get_title3    ;yes, title text missing.
  493.     cmp    al,'"'          ;delimiter found?
  494.     jne    get_title1    ;no, continue scanning
  495.     mov    ttl_flag,-1    ;indicate title specified
  496. get_title2:    lodsb        ;get next char of title
  497.     cmp    al,'"'          ;terminate if second <"> char
  498.     je    get_title3    ;or C/R found.
  499.     cmp    al,cr
  500.     je    get_title3
  501.     stosb            ;store char into page heading buffer
  502.     dec    titlecount
  503.     jnz    get_title2    ;and continue scan
  504. get_title3:  ret
  505. get_title endp
  506.  
  507.  
  508. get_date proc near        ;get date/time, insert into title
  509.     mov    ah,2Ch        ;time-of-day
  510.     int    21h
  511.     xor    ax,ax
  512.     mov    al,ch
  513.     aam            ;convert to decimal chars
  514.     add    ax,'00'
  515.     mov    heading_hh,ah
  516.     mov    heading_hh+1,al
  517.     xor    ax,ax
  518.     mov    al,cl
  519.     aam
  520.     add    ax,'00'
  521.     mov    heading_mm,ah
  522.     mov    heading_mm+1,al
  523.     mov    ah,2Ah        ;get date
  524.     int    21h
  525.     xor    ax,ax        ;clear
  526.     mov    al,dl        ;do day
  527.     aam
  528.     add    ax,'00'
  529.     mov    heading_day,ah
  530.     mov    heading_day+1,al
  531.     xor    ax,ax        ;clear
  532.     mov    al,dh        ;do month
  533.     aam
  534.     add    ax,'00'
  535.     mov    heading_month,ah
  536.     mov    heading_month+1,al
  537.     mov    ax,cx        ;do year
  538.     sub    ax,1900
  539.     aam
  540.     add    ax,'00'
  541.     mov    heading_year,ah
  542.     mov    heading_year+1,al
  543.     ret
  544. get_date endp
  545.  
  546.  
  547.  
  548. get_option proc near        ;Scan the input line and determine the
  549.                 ;run-time options (parameters).
  550.     mov    si,offset command+1  ;DS:SI=addr of command line
  551.     cld
  552. gopt00: lodsb            ;look for "/"
  553. gopt01: cmp    al,cr        ;C/R?
  554.     jne    gopt03        ;not end, continue
  555. gopt02: ret            ;exit
  556. gopt03: cmp    al,' '          ;blank?
  557.     je    gopt00        ;yes, try next
  558.     cmp    al,'"'          ;title?
  559.     jne    gopt08        ;no, continue
  560. gopt05: lodsb
  561.     cmp    al,cr
  562.     je    gopt02
  563.     cmp    al,'"'
  564.     je    gopt00
  565.     jmp    gopt05
  566. gopt08: cmp    al,'/'          ;is this and option?
  567.     je    gopt10        ;yes, process option
  568. gopt09: lodsb            ;find next parm
  569.     cmp    al,cr
  570.     je    gopt02        ;exit    ?
  571.     cmp    al,'/'
  572.     je    gopt10
  573.     cmp    al,' '          ;end of this parm?
  574.     jne    gopt09        ;no, continue
  575.     jmp    gopt00        ;yes
  576.  
  577. gopt10: lodsb            ;found, get next char
  578.     or    al,20h        ;fold to lower case
  579.  
  580.     cmp    al,'f'
  581.     jne    gopt18
  582.     lodsb
  583.     cmp    al,'='
  584.     jne    gopt01
  585.     lodsb
  586.     cmp    al,'1'
  587.     jb    gopt01
  588.     cmp    al,'5'
  589.     ja    gopt01
  590.     and    al,07h
  591.     mov    flg_font,al
  592.     jmp    gopt09
  593. gopt18:
  594.     cmp    al,'x'          ;x=translate
  595.     jne    gopt20
  596.     mov    xlate_switch,-1 ;set translate
  597.     jmp    gopt09
  598. gopt20: cmp    al,'s'          ;s=strip
  599.     jne    gopt24
  600.     mov    strip_switch,-1 ;set input-strip
  601.     jmp    gopt09
  602. gopt24: cmp    al,'t'          ;t=terminal (the console or screen)
  603.     jne    gopt26
  604.     mov    term_switch,-1 ;set print switch
  605.     jmp    gopt09
  606. gopt26: cmp    al,'i'          ;i=indent
  607.     jne    gopt30
  608.     mov    flg_indent,-1    ;set indent switch
  609.     jmp    gopt09
  610. gopt30: cmp    al,'8'
  611.     jne    gopt32
  612.     mov    flg_lpi,8    ;8 lpi
  613.     jmp    gopt09
  614. gopt32: cmp    al,'6'
  615.     jne    gopt40
  616.     mov    flg_lpi,6    ;6 lpi
  617.     jmp    gopt09
  618. gopt40: cmp    al,'n'          ;n=number (sequence numbering)
  619.     jne    gopt50
  620.     mov    num_switch,-1    ;set sequence numbering switch
  621.     jmp    gopt09
  622. gopt50: cmp    al,'c'          ;COPY
  623.     jne    gopt60
  624.     mov    flg_copy,-1
  625.     jmp    gopt09
  626. gopt60: cmp    al,'d'          ;Device spec
  627.     jne    gopt70
  628.     lodsb
  629.     cmp    al,'='
  630.     je    gopt62
  631. gopt61: jmp    gopt01
  632. gopt62: lodsb
  633.     cmp    al,'1'
  634.     jb    gopt61
  635.     cmp    al,'4'
  636.     ja    gopt61
  637.     and    al,07h
  638.     mov    printer_type,al
  639.     jmp    gopt09
  640. gopt70: cmp    al,'z'
  641.     jne    gopt80
  642.     mov    flg_no_eof,-1
  643.     jmp    gopt09
  644. gopt80: jmp    gopt09
  645.  
  646. get_option endp
  647.  
  648. set_option proc near        ;set run-time options
  649.     cld
  650.     mov    di,offset init_printer
  651.     mov    init_printer_length,0
  652.  
  653.  
  654. sopt10: cmp    printer_type,1    ;Epson
  655.     jne    sopt20
  656.     mov    al,012h
  657.     stosb
  658.     inc    init_printer_length
  659.     cmp    flg_font,1    ;10cpi?
  660.     je    sopt11        ;yes
  661.     mov    al,0fh        ;everything else
  662.     stosb
  663.     inc    init_printer_length
  664. sopt11: mov    al,01bh     ; set lines/inch vertical
  665.     stosb
  666.     mov    pagesize,60    ;assume 6 lpi
  667.     mov    al,50
  668.     cmp    flg_lpi,8
  669.     jne    sopt14
  670.     mov    pagesize,80    ;set 8 lpi
  671.     mov    al,48
  672. sopt14: stosb
  673.     add    init_printer_length,2
  674.     jmp    sopt90
  675.  
  676. sopt20: cmp    printer_type,2    ;Gemini Star 10x
  677.     jne    sopt30
  678.     mov    al,01bh     ; set font
  679.     stosb
  680.     mov    al,042h
  681.     stosb
  682.     mov    al,1        ;10cpi
  683.     mov    bl,3
  684.     cmp    flg_font,1
  685.     je    sopt21
  686.     mov    al,2        ;12cpi
  687.     mov    bl,4
  688.     cmp    flg_font,2
  689.     je    sopt21
  690.     mov    al,3        ;15,17cpi -- and everything else
  691.     mov    bl,5
  692. sopt21: stosb
  693.     mov    al,01bh     ;set indent
  694.     stosb
  695.     mov    al,04dh
  696.     stosb
  697.     mov    al,0
  698.     cmp    flg_indent,0
  699.     je    sopt22
  700.     mov    al,bl
  701. sopt22: stosb
  702.     mov    al,01bh     ; set lines/inch vertical
  703.     stosb
  704.     mov    pagesize,60    ;assume 6 lpi
  705.     mov    al,50
  706.     cmp    flg_lpi,8
  707.     jne    sopt24
  708.     mov    pagesize,80    ;set 8 lpi
  709.     mov    al,48
  710. sopt24: stosb
  711.     add    init_printer_length,8
  712.     jmp    sopt90
  713.  
  714. sopt30: cmp    printer_type,3    ;NEC p6/p7
  715.     je    sopt31
  716.     jmp    sopt40
  717. sopt31: mov    al,012h     ;cancel condensed
  718.     stosb
  719.     inc    init_printer_length
  720.     mov    bl,0
  721.     cmp    flg_font,1    ;10cpi
  722.     jne    sopt32
  723.     mov    al,01bh
  724.     stosb
  725.     mov    al,05dh
  726.     stosb
  727.     add    init_printer_length,2
  728.     mov    bl,3
  729.     jmp    sopt36
  730. sopt32: cmp    flg_font,2    ;12cpi
  731.     jne    sopt33
  732.     mov    al,01bh
  733.     stosb
  734.     mov    al,04dh
  735.     stosb
  736.     add    init_printer_length,2
  737.     mov    bl,4
  738.     jmp    sopt36
  739. sopt33: cmp    flg_font,3    ;15cpi
  740.     jne    sopt34
  741.     mov    al,01bh
  742.     stosb
  743.     mov    al,067h
  744.     stosb
  745.     add    init_printer_length,2
  746.     mov    bl,5
  747.     jmp    sopt36
  748. sopt34: cmp    flg_font,4    ;17cpi
  749.     jne    sopt35
  750.     mov    al,01bh
  751.     stosb
  752.     mov    al,05dh
  753.     stosb
  754.     mov    al,0fh
  755.     stosb
  756.     add    init_printer_length,3
  757.     mov    bl,5
  758.     jmp    sopt36
  759. sopt35: cmp    flg_font,5    ;20cpi
  760.     jne    sopt36
  761.     mov    al,01bh
  762.     stosb
  763.     mov    al,04dh
  764.     stosb
  765.     mov    al,0fh
  766.     stosb
  767.     add    init_printer_length,3
  768.     mov    bl,6
  769.     jmp    sopt36
  770. sopt36: mov    al,01bh     ;set indent
  771.     stosb
  772.     mov    al,06ch
  773.     stosb
  774.     mov    al,0
  775.     cmp    flg_indent,0
  776.     je    sopt37
  777.     mov    al,bl
  778. sopt37: stosb
  779.     add    init_printer_length,3
  780.     mov    al,01bh     ; set lines/inch vertical
  781.     stosb
  782.     mov    pagesize,60    ;assume 6 lpi
  783.     mov    al,50
  784.     cmp    flg_lpi,8
  785.     jne    sopt39
  786.     mov    pagesize,80    ;set 8 lpi
  787.     mov    al,48
  788. sopt39: stosb
  789.     add    init_printer_length,2
  790.     jmp    sopt90
  791.  
  792. sopt40: cmp    printer_type,4    ;IBM Proprinter
  793.     jne    sopt50
  794.     cmp    flg_font,1    ;10cpi
  795.     jne    sopt42
  796.     mov    al,012h
  797.     stosb
  798.     inc    init_printer_length
  799.     jmp    sopt46
  800. sopt42: cmp    flg_font,2    ;12cpi
  801.     jne    sopt43
  802.     mov    al,01bh
  803.     stosb
  804.     mov    al,03ah
  805.     stosb
  806.     add    init_printer_length,2
  807.     jmp    sopt46
  808. sopt43:             ;17cpi and everything else
  809.     mov    al,0fh
  810.     stosb
  811.     inc    init_printer_length
  812.     jmp    sopt46
  813. sopt46:
  814.     mov    al,01bh     ; set lines/inch vertical
  815.     stosb
  816.     mov    pagesize,60    ;assume 6 lpi
  817.     mov    al,50
  818.     cmp    flg_lpi,8
  819.     jne    sopt49
  820.     mov    pagesize,80    ;set 8 lpi
  821.     mov    al,48
  822. sopt49: stosb
  823.     add    init_printer_length,2
  824.     jmp    sopt90
  825. sopt50:
  826.     jmp    sopt90
  827.  
  828. sopt90:
  829.     ret
  830. set_option endp
  831.  
  832.  
  833. open_input proc near        ;open the input file
  834.     mov    dx,offset input_name  ;DS:DX=addr filename
  835.     mov    al,0        ;read-only
  836.     mov    ah,3dh        ;function=3dh for open
  837.     int    21h        ;handle return in ax
  838.     mov    input_handle,ax ;save it for later
  839.     ret            ;CY is set if error
  840. open_input endp
  841.  
  842.  
  843. get_char proc near        ;get one char from input buffer
  844. get_char0:
  845.     mov    bx,input_ptr    ;is pntr at end of buffer?
  846.     cmp    bx,blksize
  847.     jne    get_char1    ;no
  848.     call    read_block    ;yes, new block must be read
  849.     mov    bx,0        ;init pntr
  850.     mov    input_ptr,bx
  851.     cmp    input_buffer_len,0  ;end?
  852.     jne    get_char1    ;no, continue
  853.     mov    al,eof
  854.     ret
  855. get_char1: mov    al,[input_buffer+bx]
  856.     inc    bx        ;inc pntr
  857.     mov    input_ptr,bx
  858.     cmp    al,20h        ;is it a control code?
  859.     jae    get_char6    ;no, continue.
  860.     cmp    flg_no_eof,0
  861.     je    get_char9    ;not skiping eof's
  862.     cmp    al,eof
  863.     je    get_char0
  864.     ret
  865. get_char6: cmp strip_switch,0    ;stripping?
  866.     je    get_char7    ;no
  867.     and    al,7fh        ;yes
  868.     ret
  869. get_char7: cmp    xlate_switch,0    ;translating?
  870.     je    get_char9
  871.     cmp    al,80h        ;special char?
  872.     jae    get_char8    ;yes
  873.     ret            ;no
  874. get_char8: mov    bx,0        ;yes, do xlate
  875.     mov    bl,al
  876.     mov    al,[Xtbl+bx]
  877.     ret
  878. get_char9:
  879.     ret
  880. get_char endp
  881.  
  882.  
  883. put_char proc near        ;put one char into output buffer
  884.     mov    bx,output_ptr
  885.     mov    [output_buffer+bx],al  ;insert char in buffer
  886.     inc    output_ptr    ;and update pntr/counter
  887.     ret
  888. put_char endp
  889.  
  890.  
  891. read_block proc near        ;read block of data from input file
  892.     mov    bx,input_handle
  893.     mov    cx,blksize
  894.     mov    dx,offset input_buffer
  895.     mov    ah,3fh
  896.     int    21h
  897.     jnc    read_block1    ;if no error
  898.     mov    ax,0        ;fake zero length if error
  899. read_block1:
  900.     mov    input_buffer_len,ax
  901.     cmp    ax,blksize    ;was a full buffer read?
  902.     je    read_block2    ;yes
  903.     mov    bx,ax        ;no, store e-o-f mark
  904.     mov    byte ptr [input_buffer+bx],eof
  905. read_block2: mov input_ptr,0    ;init pntr to input buffer
  906.     ret
  907. read_block endp
  908.  
  909.  
  910. write_maybe proc near        ;output line if buffer contains anything
  911.     mov    ax,output_ptr    ;pntr is non-zero if data in buffer
  912.     or    ax,ax
  913.     jz    write_maybe1    ;nothing, exit
  914.     call    write_line    ;something is there, output it.
  915. write_maybe1: ret
  916. write_maybe  endp
  917.  
  918.  
  919. write_line    proc near    ;transmit contents of output buffer to
  920.                 ;the standard list device.
  921.  
  922.     cmp    num_switch,0
  923.     je    write_line5
  924.     inc    linenumber
  925.     mov    ax,linenumber
  926.     mov    bx,offset output_number
  927.     call    Convert
  928. write_line5:
  929.     mov    cx,output_ptr    ;CX contains length of string
  930.     mov    dx,offset output_buffer ;DX:DX=buffer addr
  931.     cmp    num_switch,0
  932.     je    write_line7
  933.     add    cx,6
  934.     mov    dx,offset output_number
  935. write_line7:
  936.     mov    bx,output_handle;BX=handle for standard list device.
  937.     mov    ah,40h        ;function 40h = write to device
  938.     int    21h
  939.     inc    linecount    ;for lines/page
  940.     mov    output_ptr,0    ;reset buffer pntr
  941.     ret
  942. write_line endp
  943.  
  944.  
  945. heading_maybe proc near     ;print heading if linecount justifies it
  946.     cmp    flg_copy,0
  947.     jne    heading_maybe2    ;skip ff if just on linecount
  948.     mov    ax,linecount
  949.     cmp    ax,pagesize
  950.     jb    heading_maybe2    ;page not full yet.
  951.     call    print_heading    ;FormFeed and print heading
  952. heading_maybe2: ret
  953. heading_maybe    endp
  954.  
  955.  
  956. print_heading proc near     ;PRINT FormFeed, title and Page Number
  957.     inc    pagecount    ;update page number
  958.     mov    ax,pagecount    ;get it and convert to ascii
  959.     mov    bx,offset heading2
  960.     call    Convert
  961.     mov    dx,offset heading_buffer ;now print the heading string
  962.     mov    cx,heading_length
  963.     cmp    flg_copy,0
  964.     je    print_heading_3
  965.     mov    cx,1
  966. print_heading_3:
  967.     mov    bx,output_handle
  968.     mov    ah,40h
  969.     int    21h
  970.     test    term_switch,-1    ;console output?
  971.     jne    print_heading_5
  972.     mov    al,ff        ;printer, set formfeed after first one.
  973.     mov    heading_buffer,al
  974. print_heading_5:
  975.     mov    linecount,heading_lines  ;init line count
  976.     mov    column,0    ;and column counter
  977.     ret
  978. print_heading endp
  979.  
  980. Convert proc near        ;convert binary to ASCII
  981.     push    dx
  982.     push    si
  983.     mov    cx,5
  984. Conv1:    mov    byte ptr [bx],' '  ;clear buffer
  985.     inc    bx
  986.     loop    Conv1
  987.     mov    si,10           ;to get digits
  988.     or    ax,ax           ;force positive
  989.     jns    conv5
  990.     neg    ax
  991. Conv5:    sub    dx,dx
  992.     div    si           ;divide by 10
  993.     add    dx,'0'
  994.     dec    bx
  995.     mov    [bx],dl        ;insert digit into output
  996.     or    ax,ax           ;if zero, done
  997.     jnz    Conv5
  998.     pop    si
  999.     pop    dx
  1000.     ret
  1001. Convert endp
  1002.  
  1003. xprt    ends
  1004.  
  1005.     end main
  1006.  
  1007.